package pe.com.pgn.consolidadorventas.servidorcentral.dbo.procedures;

import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import pe.com.pgn.consolidadorventas.servidorcentral.util.LoggerUtil;

public class ProcedureNoResultSet implements HibernateCallback<Integer>{

	static Logger logger = Logger.getLogger(ProcedureNoResultSet.class);
	
	String queryProcedure;
	
	public ProcedureNoResultSet(){
		queryProcedure = "";
	}
	
	public Integer doInHibernate(Session sesion) throws HibernateException,SQLException {
		SQLQuery sq =sesion.createSQLQuery(queryProcedure);
		int rs = -1;
		try{
			LoggerUtil.info(logger,">>Inicia ejecucion procedimiento : "+queryProcedure);
			rs = sq.executeUpdate();
			LoggerUtil.info(logger,">>Fin ejecucion procedimiento : "+queryProcedure);
		}catch(Exception e){
			rs = 0;
			LoggerUtil.error(logger,"Error al ejecutar el procedimiento : "+queryProcedure+"\n"+e.getMessage());
		}
		return rs;
	}

	public String getQueryProcedure() {
		return queryProcedure;
	}

	public void setQueryProcedure(String queryProcedure) {
		this.queryProcedure = queryProcedure;
	}
	
}